package com.hibase.core.rule.web.ruletable;


import com.hibase.common.entity.ResponseModel;
import com.hibase.core.rule.entity.ruletable.query.RuleTableDataChangeVO;
import com.hibase.core.rule.entity.ruletable.query.TableQuerySearchVO;
import com.hibase.core.rule.service.ruletable.RuleTableQueryService;
import com.hibase.core.web.annotation.HibasePostRequestMapping;
import com.hibase.core.web.entity.OperationIdsEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 描述:
 * 动态表查询
 *
 * @author li-wei-hua
 * @date 2020-04-08 15:18
 */
@RestController
@RequestMapping("/rule-table-query")
@Api(tags = "动态表查询控制")
public class RuleTableQueryController{

    @Autowired
    private RuleTableQueryService ruleTableQueryService;

    @ApiOperation(value = "查询动态表", httpMethod = "POST")
    @HibasePostRequestMapping(value = "selectTable")
    public ResponseModel selectTable(@RequestBody TableQuerySearchVO searchVO){

        return ResponseModel.successMsg(ruleTableQueryService.selectTableData(searchVO));
    }

    @ApiOperation(value = "添加数据到动态表",httpMethod = "POST")
    @HibasePostRequestMapping(value = "changeData")
    public ResponseModel changeData(@RequestBody RuleTableDataChangeVO insertVO){

        ruleTableQueryService.changeData(insertVO);

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "删除动态表数据",httpMethod = "POST")
    @HibasePostRequestMapping(value = "deleteData")
    public ResponseModel deleteData(@RequestBody OperationIdsEntity idsEntity){

        ruleTableQueryService.deleteData(idsEntity);

        return ResponseModel.successMsg();
    }

    @ApiOperation(value = "修改数据到动态表(单条)",httpMethod = "POST")
    @HibasePostRequestMapping(value = "updateData")
    public ResponseModel updateData(@RequestBody Map<String,Object> updateVO){

        ruleTableQueryService.updateData(updateVO);

        return ResponseModel.successMsg();
    }

}
